//
//  CurlViewController.swift
//  UI
//
//  Created by admin on 14/9/18.
//  Copyright (c) 2014年 sinosun. All rights reserved.
//

import UIKit

class CurlViewController: UIViewController {

    override func viewDidLoad() {
        super.viewDidLoad()

        // Do any additional setup after loading the view.
        var segment = UISegmentedControl(items: ["up", "down"])
        segment.selectedSegmentIndex = 0
        self.navigationItem.titleView = segment
        
        self.navigationItem.rightBarButtonItem = UIBarButtonItem(title: "翻页", style: UIBarButtonItemStyle.Bordered, target: self, action: "page")
        
        
    }
    
    
    func page(){
    
        UIView.beginAnimations("page", context: nil)
        UIView.setAnimationCurve(UIViewAnimationCurve.EaseInOut)
        UIView.setAnimationDuration(1.0)
        
        switch (self.navigationItem.titleView as UISegmentedControl).selectedSegmentIndex{
        case 0:
            UIView.setAnimationTransition(UIViewAnimationTransition.CurlUp, forView: self.view, cache: true)
            println()
        case 1:
            UIView.setAnimationTransition(UIViewAnimationTransition.CurlDown, forView: self.view, cache: true)
            println()
        default:
            UIView.setAnimationTransition(UIViewAnimationTransition.CurlUp, forView: self.view, cache: true)
            println("default")
        }
        
        
        self.view.exchangeSubviewAtIndex(0, withSubviewAtIndex: 1)
        
        
        UIView.commitAnimations()
    }

    override func didReceiveMemoryWarning() {
        super.didReceiveMemoryWarning()
        // Dispose of any resources that can be recreated.
    }
    

    /*
    // MARK: - Navigation

    // In a storyboard-based application, you will often want to do a little preparation before navigation
    override func prepareForSegue(segue: UIStoryboardSegue!, sender: AnyObject!) {
        // Get the new view controller using segue.destinationViewController.
        // Pass the selected object to the new view controller.
    }
    */

}
